package com.hsteach.web.controller.equipment;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.dao.domain.equipment.EquipmentRepairConfig;
import com.hsteach.service.equipment.EquipmentRepairConfigService;
import com.hsteach.web.controller.equipment.dto.AddEquipmentConfigDto;
import com.hsteach.web.controller.equipment.dto.UpdateEquipmentConfigDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "设备维修配置", tags = "设备维修配置")
@RestController
@RequestMapping("/equipment/repairConfig")
public class EquipmentRepairConfigController extends BaseController {

    @Autowired
    private EquipmentRepairConfigService equipmentRepairConfigService;

    /**
     * 根据启用状态查询维修配置列表
     * @param status
     * @return
     */
    @ApiOperation("根据启用状态查询维修配置列表")
    @PostMapping("/list")
    public TableDataInfo<EquipmentRepairConfig> list(@RequestParam("status") int status ){
       return getDataTable( equipmentRepairConfigService.queryListByStatus(status));
    }

//    /**
//     * 新增维修配置
//     * @param equipmentRepairConfig
//     * @return
//     */
//    @ApiOperation("新增维修配置")
//    @PostMapping("/add")
//    public AjaxResult add(@RequestBody EquipmentRepairConfig equipmentRepairConfig){
//       return toAjax(equipmentRepairConfigService.add(equipmentRepairConfig));
//    }

    /**
     * 新增维修配置
     * @param dto
     * @return
     */
    @ApiOperation("新增维修配置")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AddEquipmentConfigDto dto){
        return toAjax(equipmentRepairConfigService.addList(dto));
    }

    /**
     * 更新维修配置
     * @param dto
     * @return
     */
    @ApiOperation("更新维修配置")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody UpdateEquipmentConfigDto dto){
        return toAjax(equipmentRepairConfigService.edit(dto));
    }

    /**
     * 更新维修配置
     * @param type
     * @return
     */
    @ApiOperation("根据类型查询所有人员")
    @GetMapping("/byType")
    public TableDataInfo byType(@Param("repairType") String type){
        return getDataTable(equipmentRepairConfigService.getPersonByType(type));
    }

    /**
     * 更新维修配置
     * @param searchName
     * @return
     */
    @ApiOperation("查询所有维修工")
    @GetMapping("/allPerson")
    public TableDataInfo allPerson(@Param("searchName") String searchName){
        return getDataTable(equipmentRepairConfigService.getAllRepairPerson(searchName));
    }
}
